import { observable, action } from "mobx-miniprogram"
import { request } from "../utils/util";

export const store = observable({
    active: 'pages/index/index',
    licks: [],
    get info() {
        return this.licks.length
    },
    get getList() {
        const that = this
        let list = ""
        for (let i = 0; i < that.licks.length; i++) {
            if (i === 0) {
                list = that.licks[i]
            }
            list = list + ',' + that.licks[i]
        }
        // console.log('id数组', list);
        request('/song/detail', 'GET', {
            ids: list
        })
            .then(data => {
                // console.log('id数组', data.songs, that, this);
                this.songList = data.songs
            })
            .catch(err => {
                console.error(err)
                this.songList = []
            })
        return that.songList
    },
    changePath: action(function (path) {
        // console.log('changePath初始数据', path, this.active)
        this.active = path
    }),

    addLick(lick) {
        // console.log('收藏的数据：', lick);
        if (!this.licks.includes(lick)) {
            this.licks = [...this.licks, lick]
        }
        // console.log('this.licks', this.licks)
    },
    deteleTLick(id) {
        console.log('asdfas',id);
        this.licks = this.licks.filter(item => item !== id)
        console.log('删除数据：', this.licks);
    }

})